<?php
$microtime            = microtime(true);
$curr_time            = date("Y-m-d H:i:s");
include_once("logins.php");
$what_to_do           = 8;
$s                    = 0; # current send login
$max_chip             = 5; # max change ip
$max_proxy_failed     = 6; # from 0
$user_agent           = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
$timeout              = 15;

$gid                  = "8632383";
$table                = "my_club8632383";

$day_trigger          = 1;
$is_debug             = 1;
$is_need_send_offline = 0;
$is_event             = 0;
$is_browser           = FALSE;
$is_need_cookie       = 1;
$day                  = 27; # текущий день

if($is_browser) { echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /><pre>\n"; }
echo "[".$curr_time."]\n";
include_once("class_main_curl.php");
include_once("functions.php");

$vk_dir = "/home/fox/dev/mvk2/";
if($is_browser) { $temp_dir = "temp-www/"; } else { $temp_dir = "temp-cli/"; }
$obj_curl  = new main_curl();

///// main loop
$i = 0;
switch($what_to_do) {
	case 0: # get lcm cookies
		system("rm -rf ".$vk_dir.$temp_dir."*yandex.ru");
		get_lmcookies(20);
		break;
	
	case 1:
		system("rm -rf ".$vk_dir.$temp_dir."1search/"."*yandex.ru");
		get_smcookies(10);
		break;

	case 111:
		system("rm -rf ".$vk_dir.$temp_dir."1real/"."*yandex.ru");
		system("rm -rf ".$vk_dir.$temp_dir."1real/"."mishakotov2009@gmail.com");
		get_rmcookies(20);
		break;		
		
	case 2: # send invites
		$mysql_query  = "SELECT id_vk, flag, year, day, name FROM `".$table."` WHERE flag=1 AND ";
		$mysql_query .= "`curr_time` > '2009-03-27 00:40:00' ORDER BY day ASC";
		do_lmsend_invites(20);
		break;

	case 3: # multi search 
		do_smsearch(20);
		break;

	case 4: # check new messages
		unset($obj_curl->proxy);
		//system("rm -rf ".$vk_dir.$temp_dir."*"); # с svn нельзя использовать
		//system("mkdir ".$vk_dir.$temp_dir."cookies");
		$la = $lgm_arr; // logins array
		$pa = $pgm_arr; // passes array
		$ga = $group_arr;
		do {
			if(!is_dir($temp_dir.$la[$i])) { mkdir($temp_dir.$la[$i]); }
			echo "----------------------[".$la[$i]."]----------------------\n"; eflush();
			$obj_curl->cookie = $temp_dir.$la[$i]."/cookie.txt";
			$obj_curl->filename = $temp_dir.$la[$i]."/index.html";
			if($is_need_cookie == 1) {
				system("rm -rf ".$vk_dir.$temp_dir.$la[$i]."/*.html"); # это место спорно
				system("rm -rf ".$vk_dir.$temp_dir.$la[$i]."/*.txt");
				get_cookies($la[$i], $pa[$i]);
			}

			get_friends($la[$i]);
			get_messages($la[$i]);
			get_group_wall($i);  # новое поколение функций использует только необходимый параметр $i
			get_topic_mess($i);

			//get_groups($la[$i]); # вроде как работает - но это почти не нужн
			//do_wsearch($la[$i]); # поиск новых людей

			# ещё не реализованные функции:
			//create_info($la[$i]);
			//get_wall($la[$i]);   # ещё не написано

			$i++;
		} while ($i < count($la));
		break;

	case 5: # create info for lcm
		$i = 0;
		$obj_curl->proxy = FALSE;
		do {
			$obj_curl->cookie = $temp_dir.$lcm_arr[$i]."/cookie.txt";
			echo "[i=".$i."] ".$lcm_arr[$i]."\n"; eflush();
			create_info($lcm_arr[$i]);
			echo "--------------------------------------------------------------------------\n"; eflush();
			$i++;
		} while ($i < count($lcm_arr));
		break;

	case 6: # create info for scm
		$i = 0;
		$obj_curl->proxy = FALSE;
		do {
			$obj_curl->cookie = $temp_dir."1search/".$scm_arr[$i]."/cookie.txt";
			echo "[i=".$i."] ".$scm_arr[$i]."\n"; eflush();
			create_info_scm($scm_arr[$i]);
			echo "--------------------------------------------------------------------------\n"; eflush();
			$i++;
		} while ($i < count($scm_arr));
		break;		

	case 7: # change info
		$cm_arr = $lcm_arr;
		$path1 = $temp_dir;
		//$path1 = $path1."1search/";
		//$path1 = $path1."1real/";
		for($i = 2; $i < count($cm_arr); $i++) {
			echo "[i=".$i."] ".$cm_arr[$i]."\n";
			$path = $path1.$cm_arr[$i]."/";			
			change_info($path);
		}
		break;
	
	case 777: # change info for 1 acc
		change_info($temp_dir."1real/mkgroup2009@gmail.com/");
		break;
		
	case 8: # get multicurl messages
		$i = 0;
		do {
			echo "-----[i=".$i."] ".$rcm_arr[$i]."\t";
			get_messages($i);
			//echo "--------------------------------------------------------------------------\n"; eflush();
			$i++;
		} while ($i < 20);
		break;
		
	case 11:
		get_mmcookies_durov($lcm_arr, $pcm_arr, 50);
		break;
	
	case 12:
		get_durov();
		break;
	
	case 13:
		event_enter($lcm_arr, 50);
		break;
	
	case 14:
		event_leave($lcm_arr, 50);
		break;
}

echo "[[[[  [[  [  ".(microtime(true) - $microtime)."  FINISHED  ]  ]]  ]]]]\n";
if($is_browser) { echo "</pre>\n"; }
?>
